//
//  WYCPreviewViewController.m
//  掌上还
//
//  Created by 王晓民 on 2018/1/17.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "WYCPreviewViewController.h"
#import "repayPlanViewCell.h"
#import "repayModel.h"
#import "amountModel.h"
#import "configuration.h"
@interface WYCPreviewViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong) NSString *total;
@property(nonatomic,strong)UILabel *Statement1;
@property(nonatomic,strong) UILabel *Repaymentlabel1;
@property(nonatomic,strong) NSString *planNo;
@property(nonatomic,strong)UIView  *introView;
@property(nonatomic,strong)UIView * showView;
@end

@implementation WYCPreviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
   

    [self setupNav];
    [self setupTableView];
    //网络请求
    [self loadplan];
    self.dataArray = [[NSMutableArray alloc] init];
    
    self.detailsArray = [[NSMutableArray alloc] init];
}

#pragma mark ------>>创建tableview
- (void)setupTableView{

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavHeight, ScreenWidth,ScreenHeight-64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = WYCGlobalBg;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
}



- (void)setupNav {
    [self.navigationController.navigationBar setBarTintColor:wycMain];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationItem.title = @"计划明细";
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1 ;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  self.dataArray.count ;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString * strID = @"cell";
    
   repayPlanViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strID];

    if (cell == nil)
    {

        cell=[[[NSBundle mainBundle]loadNibNamed:@"repayPlanViewCell" owner:self options:nil]lastObject];

    }
    
    repayModel * model = self.dataArray[indexPath.row];
    
    cell.consumeDateLb.text = model.executeTime;
   
    cell.poundageLb.text = [NSString stringWithFormat:@"手续费:￥%.1f",[ model.poundage doubleValue]];
  
    NSString  *tye = model.type;
    //消费
    if ([tye isEqualToString:@"1"]) {
        cell.typeImg.image = [UIImage imageNamed:@"consumption"];
        cell.planAmountLb.text=[NSString stringWithFormat:@"￥%.1f" ,[model.amount doubleValue]];
    }
    else
    {
        cell.typeImg.image = [UIImage imageNamed:@"repayment"];
        cell.planAmountLb.text=[NSString stringWithFormat:@"￥%.1f" ,[model.amount doubleValue]];
    }

    return cell;
}

-(void)loadplan
{
    [HttpTool POST:createPlan params:_parmDic success:^(NSURLSessionDataTask *task, id responseObject) {

        NSLog(@"预览计划%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
            NSDictionary * result = responseObject[@"result"];

            NSArray * dataArray = result[@"detail"];
            NSLog(@"%@",dataArray);
            for (NSDictionary * dic in dataArray) {
                repayModel * taranLationModel = [repayModel mj_objectWithKeyValues:dic];
                [self.dataArray addObject:taranLationModel];
            }
        }
        
        [self.tableView reloadData];


    } fail:^(NSURLSessionDataTask *task, NSError *error) {

    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
